1 using System;
2 #
if UNITY_EDITOR
3 using
UnityEditor;
4 #endif

5 using
UnityEngine;
6
7
8 namespace
UnityStandardAssets.CrossPlatformInput
9 {
10     
[ExecuteInEditMode]
11     
public class MobileControlRig : MonoBehaviour
12     {
13         
// this script enables or disables the child objects of a control rig
14         
// depending on whether the USE_MOBILE_INPUT define is declared.
15
16         
// This define is set or unset by a menu item that is included with
17         
// the Cross Platform Input package.
18
19
20 #
if !UNITY_EDITOR
21     
void OnEnable()
22     {
23         CheckEnableControlRig();
24     }
25 #endif
26
27         
private void Start()
28         {
29 #
if UNITY_EDITOR
30             
if (Application.isPlaying) //if in the editor, need to check if we are playing, as start is also called just after exiting play
31 #endif
32             {
33                 UnityEngine.EventSystems.EventSystem system = GameObject.FindObjectOfType<UnityEngine.EventSystems.EventSystem>();
34
35                 
if (system == null)
36                 {
//the scene have no event system, spawn one
37                     GameObject o =
new GameObject("EventSystem");
38
39                     o.AddComponent<UnityEngine.EventSystems.EventSystem>();
40                     o.AddComponent<UnityEngine.EventSystems.StandaloneInputModule>();
41                 }
42             }
43         }
44
45 #
if UNITY_EDITOR
46
47         
private void OnEnable()
48         {
49             EditorApplication.update += Update;
50             EditorUserBuildSettings.activeBuildTargetChanged += Update;
51         }
52
53
54         
private void OnDisable()
55         {
56             EditorApplication.update -= Update;
57             EditorUserBuildSettings.activeBuildTargetChanged -= Update;
58         }
59
60
61         
private void Update()
62         {
63             CheckEnableControlRig();
64         }
65 #endif
66
67
68         
private void CheckEnableControlRig()
69         {
70 #
if MOBILE_INPUT
71         EnableControlRig(
true);
72         #
else
73             EnableControlRig(
false);
74 #endif
75         }
76
77
78         
private void EnableControlRig(bool enabled)
79         {
80             
foreach (Transform t in transform)
81             {
82                 t.gameObject.SetActive(enabled);
83             }
84         }
85     }
86 }


Gõ tìm kiếm nhanh...